function plotspectra(data, bins, fname)
    fields = fieldnames(data);
    timer = data.time
    if(ismember('Particles', fields))
        ndata = data.Particles.Ek;
        species = fieldnames(ndata);
        for i = 1: size(species)
            spname = species{i};
            newname = strcat('data.Particles.Ek.', spname);
            newname = strcat(newname, '.data');
            wtname = strcat('data.Particles.Weight.', spname);
            wtname = strcat(wtname, '.data');
            %newname = newname{1}
            newname = eval(newname);
            %wtname = wtname{1};
            wtname = eval(wtname);
            ans = myhist(newname, wtname, bins);
            fig = figure();
            set(fig, 'visible', 'off');
            plot(ans(:, 1), ans(:, 2), 'LineWidth', 1.5);
            xlabel('Ek in MeV');
            ylabel('Counts');
            spectraname = ['Spectra of ', spname, ' ', num2str(timer), ' sec'];
            %strcat('Spectra of ', spname)
            title(spectraname);
            set(gca, 'FontSize', 13, 'LineWidth', 1.5);
            nfname = [fname, '_', spname, '.jpg'];
            saveas(fig, nfname, 'jpg');
        end
    end
end

            
        
    
